package com.dom.domweb.modular.controller.sysmger;

import com.dom.common.model.vo.basic.B130R;
import com.dom.common.model.vo.basic.B133A;
import com.dom.common.model.vo.basic.B139A;
import com.dom.common.model.vo.basic.B139R;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.dao.service.ITMeasureUnitTblService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品单位控制器
 * @author zhuwei
 * @Date 2018-11-17
 */
@RestController
@RequestMapping("/base")
public class UnitController {

    @Autowired
    private ITMeasureUnitTblService unitTblService;

    @RequestMapping("/getUnitInfoList")
    public TabPager getUnitInfoList(@RequestParam("limit")int limit, @RequestParam("page")int page){
        B139R request = new B139R();
        request.setPn(page);
        request.setPs(limit == 0 ? 20 : limit);
        B139A result = unitTblService.getUnitInfoList(request);
        return new TabPager(result.getUnitData(),result.getTotalNum());
    }

    @RequestMapping("/getAllUnitInfo")
    public RspModel getAllUnitInfo(){
        B139A result = unitTblService.getAllUnitInfo();
        return new RspModel(result.getUnitData());
    }

    @RequestMapping("/getUnitInfoByCode")
    public RspModel getUnitInfoByCode(@RequestParam("id") String id){
        B133A result = unitTblService.getUnitInfoByCode(id);
        return new RspModel(result);
    }
    @RequestMapping("/insertUnitInfo")
    public RspModel insertUnitInfo(@RequestBody B130R request){
        return unitTblService.insertUnitInfo(request);
    }

    @RequestMapping("/updateUnitInfo")
    public RspModel editUnitInfo(@RequestBody B130R request){
        return unitTblService.editUnitInfo(request);
    }

    @RequestMapping("/unitInfoDel")
    public RspModel unitInfoDel(@RequestParam("id")String id){
        return unitTblService.unitInfoDel(id);
    }
}
